﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace AuctionServer
{
    public class Program
    {
        private static ServiceHost _host;

        static void Main(string[] args)
        {
            try
            {
                if (_host == null || _host.State.ToString() == "Closed")
                {
                    _host = new ServiceHost(typeof (AuctionService));
                    _host.Open();
                    Console.WriteLine("Service is running");
                    Console.WriteLine("Press any key to close service");
                    Console.ReadLine();
                    
                }
                //ServiceHost host = new ServiceHost(typeof(AuctionService), new Uri("net.tcp://localhost:8080/AuctionService"));

                //ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                
                //smb.HttpGetEnabled = true;
                //smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                //host.Description.Behaviors.Add(smb);

                //host.Open();

                //Console.WriteLine("The service is ready at {0}", host.BaseAddresses[0]);
                //Console.WriteLine("Press <Enter> to stop the service.");
                //Console.ReadLine();

                //// Close the ServiceHost.

                //host.Close();
            }
            catch (CommunicationObjectFaultedException ex)
            {
                Console.WriteLine(ex);
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine(ex);
            }
            catch (ObjectDisposedException ex)
            {
                Console.WriteLine(ex);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            //Console.WriteLine("Server Closed! Press Anykey to continue!");
            //Console.ReadKey();
        }
    }
}
